<template>

  <div >
<!--    :rules="rules"-->
    <el-form :model="accidentRecord" status-icon  style="width: 50%" ref="accidentRecordFrom" label-width="100px" class="demo-ruleForm">
      <el-form-item label="车牌号" prop="carId">
        <el-input type="text" v-model="accidentRecord.carId" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="司机名称" prop="driverId">
        <el-input type="text" v-model="accidentRecord.driverId" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="发生时间" prop="accDate">
        <el-date-picker type="datetime" v-model="accidentRecord.accDate" placeholder="选择结束时间" value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%;"></el-date-picker>
      </el-form-item>
      <el-form-item label="地点" prop="accPlace">
        <el-input type="text" v-model="accidentRecord.accPlace" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="发生事故" prop="accExplain">
        <el-input type="text" v-model="accidentRecord.accExplain" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="我方车辆损坏程度" prop="weSituation">
        <el-input type="text" v-model="accidentRecord.weSituation" autocomplete="off"></el-input>
      </el-form-item>
  <el-form-item label="对方车辆损坏程度" prop="otherSituation">
        <el-input type="text" v-model="accidentRecord.otherSituation" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="事故追责" prop="result">
        <el-input type="text" v-model="accidentRecord.result" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="我方维修费用" prop="weAmount">
        <el-input type="number" v-model="accidentRecord.weAmount" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="对方维修费用" prop="otherAmount">
        <el-input type="number" v-model="accidentRecord.otherAmount" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="保险公司赔付" prop="insAmount">
        <el-input type="number" v-model="accidentRecord.insAmount" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="处理结果" prop="remarks">
        <el-input type="text" v-model="accidentRecord.remarks" autocomplete="off"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="addAccident">提交</el-button>
        <el-button @click="resetForm">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import accidentApi from "@/api/accident";
export default {
  name: "accident_record_add",
  data(){
    return{
      accidentRecord:{},
      //验证规则
      // rules: {
      //   pass: [
      //     //验证器：变量， 触发类型：失去焦点
      //     { validator: validatePass, trigger: 'blur' }
      //   ],
      //   checkPass: [
      //     { validator: validatePass2, trigger: 'blur' }
      //   ],
      //   age: [
      //     { validator: checkAge, trigger: 'blur' }
      //   ]
      // }
    }
  },
  created() {
    if (this.$route.params.id!=null){
      let id =  this.$route.params.id;
      this.queryAccidentById(id)
    }else {
      this.accidentRecord={}
    }
  },
  methods:{
    //提交
    addAccident(){
      accidentApi.
        addAccident(this.accidentRecord).
        then((response)=>{
        if ( response.success==true){
          this.$message({
            type: 'success',
            message: '添加成功!'
          });
        }
      })
    },
    queryAccidentById(id){
      accidentApi.
        queryAccidentById(id).
        then((response)=>{
          this.accidentRecord=response.data.items
      })
    },
    //重置
    resetForm(){
      this.accidentRecord={}
    },
  }
}
</script>

<style scoped>

</style>
